"""
审查记录模块序列化器
"""
from rest_framework import serializers
from django.contrib.auth.models import User
from .models import ReviewRecord


class ReviewRecordUserSerializer(serializers.ModelSerializer):
    """用户信息序列化器（用于审查记录）"""
    class Meta:
        model = User
        fields = ['id', 'username']


class ReviewRecordSerializer(serializers.ModelSerializer):
    """审查记录序列化器"""
    student = ReviewRecordUserSerializer(read_only=True)
    reviewer = ReviewRecordUserSerializer(read_only=True)
    review_type_display = serializers.CharField(source='get_review_type_display', read_only=True)
    status_display = serializers.CharField(source='get_status_display', read_only=True)
    
    class Meta:
        model = ReviewRecord
        fields = [
            'id', 'review_type', 'review_type_display', 'student', 'reviewer',
            'status', 'status_display', 'content', 'remarks', 'review_time',
            'created_at', 'updated_at'
        ]
        read_only_fields = ['id', 'created_at', 'updated_at']


class ReviewRecordListSerializer(serializers.ModelSerializer):
    """审查记录列表序列化器（简化版）"""
    student_name = serializers.CharField(source='student.username', read_only=True)
    reviewer_name = serializers.CharField(source='reviewer.username', read_only=True)
    review_type_display = serializers.CharField(source='get_review_type_display', read_only=True)
    status_display = serializers.CharField(source='get_status_display', read_only=True)
    
    class Meta:
        model = ReviewRecord
        fields = [
            'id', 'review_type', 'review_type_display', 'student_name',
            'reviewer_name', 'status', 'status_display', 'content',
            'review_time', 'created_at'
        ]
